package cn.wolfcode.shop.cloud.common;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Setter
@Getter
public class Result<T> implements Serializable {
    private int code;
    private String msg;
    private T data;
    public static final int CODE_SUCCESS=200;//成功码
    public static final String MESSAGE_SUCCESS="操作成功";//成功信息
    public static final int CODE_REEOR=500;//错误码
    public static final String MESSAGE_ERROR="系统异常";//错误信息

    public Result() {
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static<T> Result<T> success(T data){
        return new Result<>(CODE_SUCCESS, MESSAGE_SUCCESS, data);
    }

    public static<T> Result<T> error(CodeMsg codeMsg){
        return new Result<>(codeMsg.getCode(),codeMsg.getMsg() ,null);
    }

    public static<T> Result<T> defaultError(){
        return new Result<>(CODE_REEOR,MESSAGE_ERROR ,null );
    }
}

